package com.johnguo.cretatefile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

public class CreateFileSale {
	private static Random random = new Random();
	public static final String FILE_PATH = "F:/软件/框架软件/后端/carbondata/测试文件/";
	public static final Integer COUNT = 50000 * 10000;
	public static final String SPLIT = "|";
	public static final String[] NAMES = new String[] { "吕蒙", "太史慈", "黄盖", "程普", "周瑜"};

	public static final String[] BRANDS = new String[] { "联想", "ASUS", "三星", "IBM", "惠普" };

	public static final Double[] SALE_PAY = new Double[] { 8000D, 7000D, 7700D, 8500D, 8300D };

	public static void main(String... args) {
		File file = new File(FILE_PATH + File.separator + "data.dat");
		try (FileWriter out = new FileWriter(file)) {
			for (int i = 0; i < COUNT; i++) {
				String record = getRecord();
				out.write(record + "\r\n");
				// System.out.println(record);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static String getRecord() {
		String name = NAMES[random.nextInt(5)];
		String area = "北京";
		int num = random.nextInt(5);
		String brand = BRANDS[num];
		Double sale_pay = SALE_PAY[num];
		int pay_num = 1 + random.nextInt(10);
		String date = "2017-06-" + (10 + random.nextInt(19)) + " " + (10 + random.nextInt(10)) + ":"
				+ (10 + random.nextInt(50)) + ":00";
		String record = name + SPLIT + area + SPLIT + brand + SPLIT + sale_pay + SPLIT + pay_num + SPLIT
				+ (pay_num * sale_pay) + SPLIT + date;
		return record;
	}
	
//	public static void main(String...args) {
//		String record = CreateFileSale.getRecord();
//		System.out.println(record.split("\\|").length);
//	}
	
}
